﻿using AntdUI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TPressure
{
    public partial class BaseForm : AntdUI.Window
    {
        /// <summary>公共标题栏
        /// 方便修改标题
        /// </summary>
        public PageHeader Header;
        
        /// <summary>全屏显示
        /// 
        /// </summary>
        private bool _fullScreen;

        /// <summary>允许移动
        /// 
        /// </summary>
        private bool _enableMove;

        /// <summary>窗口禁止调整大小
        /// 
        /// </summary>
        /// <param name="m"></param>
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            if (this.EnableMove)
            {
            }
            else
            {
                if (m.Msg == 0x112)
                {
                    switch ((int)m.WParam)
                    {
                        //禁止双击标题栏关闭窗体
                        case 0xF063:
                        case 0xF093:
                            m.WParam = IntPtr.Zero;
                            break;

                        //禁止拖拽标题栏还原窗体
                        case 0xF012:
                        case 0xF010:
                            m.WParam = IntPtr.Zero;
                            break;

                        //禁止双击标题栏
                        case 0xf122:
                            m.WParam = IntPtr.Zero;
                            break;

                        //允许关闭按钮
                        case 0xF060:
                            //m.WParam = IntPtr.Zero;
                            break;

                        //允许最大化按钮
                        case 0xf020:
                            //m.WParam = IntPtr.Zero;
                            break;

                        //允许最小化按钮
                        case 0xf030:
                            //m.WParam = IntPtr.Zero;
                            break;

                        //禁用还原按钮
                        case 0xf120:
                            //m.WParam = IntPtr.Zero;
                            break;

                        default:
                            //m.WParam = IntPtr.Zero;
                            break;
                    }
                }
            }
            base.WndProc(ref m);
        }

        public BaseForm()
        {
            InitializeComponent();
            this.Header = this.PageHeader1;
            this.Resizable = false;
        }

        public bool FullScreen
        {
            get
            {
                return this._fullScreen;
            }
            set
            {
                this._fullScreen = value;
            }
        }

        public bool EnableMove
        {
            get
            {
                return this._enableMove;
            }
            set
            {
                this._enableMove = value;
            }
        }

        private void BaseForm_Load(object sender, EventArgs e)
        {
            if (this.FullScreen)
            {
                this.StartPosition = FormStartPosition.Manual;
                Screen primaryScreen = Screen.PrimaryScreen;
                this.MaximizedBounds = primaryScreen.WorkingArea;
                this.MinimumSize = primaryScreen.WorkingArea.Size;
                this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            }
            else
            {
                this.StartPosition = FormStartPosition.CenterScreen;
            }
        }
    }
}
